using System.Threading.Tasks;
using JoyfulHomeJourney.BackEnd.Infrastructure.Dtos.Requests;
using JoyfulHomeJourney.BackEnd.Infrastructure.Dtos.Requests.Objects;
using JoyfulHomeJourney.BackEnd.Server.Interfaces;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
namespace JoyfulHomeJourney.BackEnd.Api.Admin.Controllers
{
    public class SysCustomersController : BaseController
    {
        private readonly ISysCustomersServer _sysCustomersServer;
        public SysCustomersController(ISysCustomersServer sysCustomersServer)
        {
            _sysCustomersServer = sysCustomersServer;
        }
        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<IActionResult> Register(RegisterCustomerDto dto)
        {
            return Send(await _sysCustomersServer.RegisterAsync(dto));
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [TypeFilter(typeof(CheckLoginFilter), Arguments = new object[] { "admin" })]
        public async Task<IActionResult> Delete(RequestSysCustomersDto dto)
        {
            return Send(await _sysCustomersServer.DeleteAsync(dto));
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        [HttpPost]
        [TypeFilter(typeof(CheckLoginFilter), Arguments = new object[] { "user" })]
        public async Task<IActionResult> Update(RequestSysCustomersDto dto)
        {
            return Send(await _sysCustomersServer.UpdateAsync(dto));
        }
        /// <summary>
        /// 分页
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        [HttpGet]
        [TypeFilter(typeof(CheckLoginFilter), Arguments = new object[] { new string[] { "admin", "carShop" } })]
        public async Task<IActionResult> Pagination(int page, int limit)
        {
            return Send(await _sysCustomersServer.PaginationAsync(page, limit));
        }
        [HttpGet]
        [TypeFilter(typeof(CheckLoginFilter), Arguments = new object[] { new string[] { "user" } })]
        public async Task<IActionResult> GetCustomerByAccount()
        {
            return Send(await _sysCustomersServer.GetCustomerByAccount(_account.AId));
        }
    }
}
